Readline Init Syntax

Contents|Index|Previous|Next
Readline init syntax

The following documentation discusses the Readline init syntax.

- Variable settings
- Key bindings
- Commands for moving
- Commands for manipulating the hisory
- Commands for changing text
- Killing and yanking
- Specifying numeric arguments

There are only four constructs allowed in the ‘˜/.inputrc’ file.

Variable settings

You can modify the run-time behavior of Readline by altering the values of variables in Readline using the set command within the init file. The following discusssion explains how to change from the default Emacs-like key binding to use vi line editing commands:

`set editing-mode vi`

A great deal of run-time behavior is changeable with the following variables.

- `bell-style`
Controls what happens when Readline wants to ring the terminal bell. If set to none, Readline never rings the bell. If set to visible, Readline uses a visible bell if one is available. If set to audible (the default), Readline attempts to ring the terminal’s bell.
- `comment-begin`
The string to insert at the beginning of the line when the insert-comment command is executed. `#` is the default value.
- `completion-ignore-case`
If set to on, Readline performs filename matching and completion in a case-insensitive fashion. `off` is the default value.
- `completion-query-items`
The number of possible completions that determines when the user is asked whether he wants to see the list of possibilities. If the number of possible completions is greater than this value, Readline will ask the user whether or not to make them viewable; otherwise, they are simply listed. The default limit is 100.
- `convert-meta`
If set to on, Readline will convert characters with the eighth bit set to an ASCII key sequence by stripping the eighth bit and prepending an Esc character, converting them to a meta-prefixed key sequence. `on` is the default value.
- `disable-completion`
If set to on, Readline will inhibit word completion. Completion characters will be inserted into the line as if they had been mapped to self-insert. `off` is the default.
- `editing-mode`
The editing-mode variable controls which default set of key bindings is used. By default, Readline starts up in Emacs editing mode, where the keystrokes are most similar to Emacs. This variable can be set to either `emacs` or `vi`.
- `enable-keypad`
When set to `on`, Readline will try to enable the application keypad when it is called. Some systems need this to enable the arrow keys. `off` is the default.
``
- `expand-tilde`
When set to `on`, tilde expansion is performed when Readline attempts word completion. `off` is the default.
- `horizontal-scroll-mode`
This variable can be set to either on or off. Setting it to on means that the text of the lines being edited will scroll horizontally on a single screen line when they are longer than the width of the screen, instead of wrapping onto a new screen line. `off` is the default.
- `keymap`
Sets Readline’s idea of the current keymap for key binding commands. Acceptable keymap names are `emacs`, `emacs-standard`, `emacs-meta`, `emacs-ctlx`, `vi`, `vi-command`, and `vi-insert`. `vi` is equivalent to `vi-command`; `emacs` is equivalent to `emacs-standard`. The default value is `emacs`.

The value of the editing-mode variable also affects the default, `keymap`.

- `mark-directories`
When set to on, completed directory names have a slash appended. `on` is the default.
- `mark-modified-lines`
This variable when set to on, says to display an asterisk (`*`) at the starts of history lines which have been modified. This variable is off by default.
- `input-meta`
If set to on, Readline will enable eight-bit input (it will not strip the eighth bit from the characters it reads), regardless of what the terminal claims it can support. The default value is `off`. The name, `meta-flag`, is a synonym for this variable.
``
- `output-meta`
If set to on, Readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence. The default is `off`.
- `print-completions-horizontally`
If set to on, Readline will display completions with matches sorted horizontally in alphabetical order, rather than down the screen. The default is `off`.
``
- `show-all-if-ambiguous`
This alters the default behavior of the completion functions. If set to on, words having more than one possible completion cause the matches to be listed immediately instead of ringing the bell. The default value is `off`.
- `visible-stats`
If set to on, a character denoting a file’s type is appended to the filename when listing possible completions. The default is `off`.
- `editing-mode`
The editing-mode variable controls which editing mode you are using. By default, GNU Readline starts up in Emacs editing mode, where the keystrokes are most similar to Emacs. This variable can either be set to emacs or vi.

- horizontal-scroll-mode
This variable can either be set to On or Off. Setting it to On means that the text of the lines that you edit will scroll horizontally on a single screen line when they are larger than the width of the screen, instead of wrapping onto a new screen line. By default, this variable is set to Off.

- mark-modified-lines
This variable when set to On, says to display an asterisk, ‘*’, at the starts of history lines which have been modified. This variable is off by default.

- prefer-visible-bell
If this variable is set to On it means to use a visible bell if one is available, rather than simply ringing the terminal bell. By default, the value is Off.

Key bindings

The syntax for controlling keybindings in the ‘˜/.inputrc’ file is simple. First you have to know the name of the command that you want to change. The following pages contain tables of the command name, the default keybinding, and a short description of what the command does.

Once you know the name of the command, simply place the name of the key you wish to bind the command to, a colon, and then the name of the command on a line in the ‘˜/.inputrc’ file. The name of the key can be expressed in different ways, depending on which is most comfortable for you.

`keyname: function-name or macro`

`keyname` is the name of a key spelled out in English. For example:

`Control-u: universal-argument`
`Meta-Rubout: backward-kill-word`
`Control-o: ">&output"`

In the example, C-U is bound to the function, universal-argument, and C-O is bound to run the macro expressed on the right hand side (that is, to insert the text ‘>&output’ into the line).

`"`keyseq`"`: function-name or macro

keyseq differs from keyname in that strings denoting an entire key sequence can be specified. Simply place the key sequence in double quotes.

GNU Emacs style key escapes can be used, as in the following example:

`"\C-u": universal-argument`
`"\C-x\C-r": re-read-init-file`
`"\e[11˜": "Function Key 1"`

In the example, C-u is bound to the function universal-argument (just as it was in the first example), C-x, C-r is bound to the function reread-init-file, and Esc-[, 1, 1, ˜ is bound to insert the text ‘Function Key 1’.

Commands for moving

beginning-of-line (C-a)

Move to the start of the current line.

end-of-line (C-e)

Move to the end of the line.

forward-char (C-f)

Move forward a character.

backward-char (C-B)

Move back a character.

forward-word (M-F)

Move forward to the end of the next word.

backward-word (M-B)

Move back to the start of this, or the previous, word.

clear-screen (C-L)

Clear the screen leaving the current line at the top of the screen.

Commands for manipulating the history

accept-line (Newline, Return)

Accept the line regardless of where the cursor is. If this line is non-empty, add it to the history list. If this line was a history line, then restore the history line to its original state.

previous-history (C-P)

Move ‘up’ through the history list.

next-history (C-N)

Move ‘down’ through the history list.

beginning-of-history (M-<)

Move to the first line in the history.

end-of-history (M->)

Move to the end of the input history, i.e., the line you are entering.

reverse-search-history (C-R)

Search backward starting at the current line and moving ‘up’ through the history as necessary. This is an incremental search.

forward-search-history (C-S)

Search forward starting at the current line and moving ‘down’ through the history as necessary.

Commands for changing text

delete-char (C-D)

Delete the character under the cursor. If the cursor is at the beginning of the line, and there are no characters in the line, and the last character typed was not C-D, then return EOF.

backward-delete-char (Rubout)

Delete the character behind the cursor. A numeric argument says to kill the characters instead of deleting them.

quoted-insert (C-Q, C-V)

Add the next character that you type to the line verbatim. This is how to insert things like C-Q for example.

tab-insert (M-TAB)

Insert a tab character.

self-insert (a, b, A, 1, !, ...)

Insert yourself.

transpose-chars (C-T)

Drag the character before point forward over the character at point. Point moves forward as well. If point is at the end of the line, then transpose the two characters before point. Negative arguments don’t work.

transpose-words (M-T)

Drag the word behind the cursor past the word in front of the cursor moving the cursor over that word as well.

upcase-word (M-U)

Uppercase all letters in the current (or following) word. With a negative argument, do the previous word, but do not move point.

downcase-word (M-L)

Lowercase all letters in the current (or following) word. With a negative argument, do the previous word, but do not move point.

capitalize-word (M-C)

Uppercase the first letter in the current (or following) word. With a negative argument, do the previous word, but do not move point.

Killing and yanking

kill-line (C-K)

Kill the text from the current cursor position to the end of the line.

backward-kill-line()

Kill backward to the beginning of the line. This is normally unbound.

kill-word (M-D)

Kill from the cursor to the end of the current word, or if between words, to the end of the next word.

backward-kill-word (M-Delete)

Kill the word behind the cursor.

unix-line-discard (C-U)

Kill the whole line the way C-U used to in Unix line input. The killed text is saved on the kill-ring.

unix-word-rubout (C-W)

Kill the word the way C-W used to in Unix line input. The killed text is saved on the kill-ring. This is different than backward-kill-word because the word boundaries differ.

yank (C-Y)

Yank the top of the kill ring into the buffer at point.

yank-pop (M-Y)

Rotate the kill-ring, and yank the new top. You can only do this if the prior command is yank or yank-pop.

Specifying numeric arguments

digit-argument (M-0, M-1, ... M--)

Add this digit to the argument already accumulating, or start a new argument. M-- starts a negative argument.

universal-argument ()

Do what C-U does in GNU Emacs. By default, this is not bound.

Top|Contents|Index|Previous|Next